<?php

use yii\grid\GridView;
use common\helpers\Url;
use common\helpers\Html;
use common\helpers\AddonHelper;

$this->title = '待办工作';
$this->params['breadcrumbs'][] = ['label' => $this->title];

?>

<div class="row">
    <div class="col-sm-12">
        <div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                <li ><a href="<?= Url::to(['index']) ?>">待办工作</a></li>
                <li class="active"><a href="<?= Url::to(['completed']) ?>">已办工作</a></li>
            </ul>
            <div class="tab-content">
                <div class="active tab-pane">
                    <?= GridView::widget([
                        'dataProvider' => $dataProvider,
                        'filterModel' => $searchModel,
                        //重新定义分页样式
                        'tableOptions' => [
                            'class' => 'table table-hover rf-table',
                            'fixedNumber' => 2,
                            'fixedRightNumber' => 1,
                        ],
                        'columns' => [
                            [
                                'class' => 'yii\grid\SerialColumn',
                                'visible' => true,
                                'headerOptions' => ['width' => '30'],
                            ],
                            'content',
                            [
                                'label' => '申请人',
                                'attribute' => 'member.realname',
                                'filter' => Html::activeTextInput($searchModel, 'member.realname', [
                                        'class' => 'form-control'
                                    ]
                                ),
                                'headerOptions' => ['class' => 'col-md-1'],
                            ],

                            [
                                'attribute' => 'created_at',
                                'filter' => \kartik\daterange\DateRangePicker::widget([
                                    'name' => 'SearchModel[created_at]',
                                    'value' => Yii::$app->request->get('SearchModel')['created_at'],
                                    'convertFormat' => true,
                                    'pluginOptions' => [
                                        'locale' => [
                                            'format' => 'Y-m-d',
                                            'separator' => '/',
                                        ],
                                    ]
                                ]),
                                'value'=>function($model){
                                    return date("Y-m-d H:i:s",$model->created_at);
                                },
                            ],
                            [
                                'attribute' => 'state',
                                'value' => function($model){
                                    return \addons\Flow\common\enums\WorkflowEnum::getValue($model->state);
                                },
                                'filter' => Html::activeDropDownList($searchModel, 'state', \addons\Flow\common\enums\WorkflowEnum::getMap(), [
                                        'prompt' => '全部',
                                        'class' => 'form-control'
                                    ]
                                )
                            ],
                            [
                                'class' => 'yii\grid\ActionColumn',
                                'header' => '操作',
                                'headerOptions' => ['width' => '250'],
                                'template' => '{approve}',
                                'buttons' => [
                                    'approve' => function ($url, $model, $key) {
                                        $ids = explode(',', $model->audit_ids);
                                        if($ids[count($ids)-1]==Yii::$app->user->id)
                                        return Html::edit(['reset', 'id' => $model->id], '重审',  [
                                                'data-toggle' => 'modal',
                                                'data-target' => '#ajaxModalLg',
                                            ]

                                        );
                                    },
                                ]
                            ]
                        ],
                    ]); ?>
                </div>
            </div>
        </div>
    </div>
</div>